<?php
require_once 'inc_security.php';
$action = getValue('action','str','POST','');
switch($action){

    case 'change_cat_combo' :
        $cat_combo = getValue('cat_combo','int','POST',0);
        $pro_array = new db_query('SELECT pro_id, pro_name FROM products WHERE pro_cat_id = '.$cat_combo);
        $pro_array = $pro_array->resultArray();
        foreach($pro_array as $combo){
            ?>
            <option value="<?=$combo['pro_id']?>"><?=$combo['pro_name']?></option>
            <?
        }
        break;

    case 'change_type_cat':
        $type = getValue('type','str','POST','');
        $list_cat = array();
        $arr_cat = $catBase = new Category;
        $list_cat = array(''=>' - Chọn danh mục - ');
        $arrCat = $catBase->list_categories(0,'cat_active = 1 AND cat_type ="'.$type . '"','cat_id,cat_name,cat_type','cat_id ASC');
        foreach($arrCat as $i=>$cat){
            $tt = '';
            for($j=0;$j<$cat["level"];$j++) $tt .= '|--';
            $list_cat[$cat["cat_id"]] = $tt . $cat["cat_name"];
        }
        foreach($list_cat as $k=>$cat){
            ?>
            <option value="<?=$k?>"><?=$cat?></option>
        <?
        }
        break;

    case 'load_type_product' :
        $pro_id = getValue('id','int','POST',0);
        $type = getValue('type','int','POST',0);
        if(!$pro_id){
            //file add product
            if($type == TYPE_PRODUCT_FULL){
                die(json_encode(array('code'=>1,'url'=>'add.php')));
            }else{
                die(json_encode(array('code'=>1,'url'=>'add_simple.php')));
            }
        }else{
            //file edit product
            if($type == TYPE_PRODUCT_FULL){
                die(json_encode(array('code'=>1,'url'=>'edit.php?record_id='.$pro_id)));
            }else{
                die(json_encode(array('code'=>1,'url'=>'edit_simple.php?record_id='.$pro_id)));
            }
        }
        break;

    case 'search_relate':
        $keyword = getValue('keyword','str','POST','');
        if(!$keyword){
            break;
        }
        echo AdminController::SearchProRelate($keyword);
    break;

}
?>